# -*- coding: utf-8 -*-
from tool import json_post, host_graphdbget, host_graphdb


if __name__ == "__main__":
    line = "line-two"

    ret = json_post(host_graphdbget(line), {
        "n": "task",
        "obj": "uid",
        "nd": [{
            "n": "pcode",
            "obj": "uid",
            }]
        })

    if ret is None:
        print("empty")
        quit()

    task = []

    for d in ret:
        task.append(d["uid"])

        if "pcode" not in d:
            continue

        pcode = d["pcode"]

        uid = d["uid"]
        tmp = []

        for p in pcode:
            tmp.append(p["uid"])

        u = ",".join(tmp)

        cmd = {
                "r": [{
                    "u": uid,
                    "v": [{"k": "pcode", "u": u}]
                    }]
                }

        json_post(host_graphdb(), cmd)

    u = ",".join(task)

    cmd = {
            "r": [{
                "u": line,
                "v": [{"k": "task", "u": u}]
                }]
            }

    json_post(host_graphdb(), cmd)
